<template>
	<div class="tabbar-user">
        <user-header @onClickShareVip="showShareVip=true"/>
        <!-- <order-group /> -->
        <!-- 卡券 -->
        <ecoupon-group />
        <!-- 个人信息 -->
        <user-module v-if="isLogin" ref="msg"/>
        <van-button size="large" class="tabbar-user__quit" v-if="isLogin" @click="quit">退出当前账户</van-button>
        <div class="share_mask" v-if="showShareVip" @click="showShareVip=false"><img src="@/assets/images/sharebg.png"></div> 
	</div>
</template>

<script>
import userHeader from "./tabbar-user-header";
// import orderGroup from "./tabbar-user-order";
import ecouponGroup from "./tabbar-user-ecoupon";
import userModule from "./tabbar-user-module";
import scrollFixed from "@/vue/mixin/scroll-fixed";
import { USER_PROFILE, } from '@/api/user';
import wxConfig from '@/vue/mixin/wx-config';
import logo from '@/assets/images/logo.jpg';
export default {
  mixins: [scrollFixed, wxConfig],
  data() {
    return {
      isLogin: false,
      showShareVip: false
    }
  },

  activated() {
    this.getLoginStatus().then(() => {
      const user = this.getUser();
      // if (user.isVip) {
      //   let vm = this;
      //   const url = vm.getUri() + 'register/invite?teamId=' + user.upshopTid +
      //     '&cid=' + user.centreId +
      //     '&redirect=' + encodeURIComponent('/user/vip?code=') + user.myCode +
      //     '&code=' + user.myCode;
      //   const title = (user.realname || user.nickname) + '邀请你升级VIP会员';
      //   vm.wxShare(title, '升级VIP会员，享受更多折扣，购物更省钱、更划算，快来升级吧！', url, location.origin + logo);
      // }
      if (!user.mobile) {
        this.$dialog.confirm({
          title: '温馨提示',
          message: '您未绑定手机号码，请尽快绑定',
        }).then(() => {
          this.$router.push({
            name: 'user-information'
          });
        }).catch(() => {});
      }
    });

    this.wxconfig();
  },
  deactivated() {
    this.isLogin = false;
  },
  //在页面离开时记录滚动的位置
		// beforeRouteEnter (to, from, next) {

		// 	next(vm=>{
    //     console.log('被迫')
    //     console.log(vm.scrollTop)
    //     vm.$nextTick(()=>{
    //       console.log(vm.$refs.componentInstance)
    //        vm.$refs.componentInstance.scrollTop = vm.scrollTop;
    //     })
		// 	})
    // },
  methods: {
    quit() {
      //添加
      this.$util.removeStorage('firstLogin');
      this.$util.removeStorage('user');
      this.$util.removeStorage('shopCenterId');
      this.$util.removeStorage('authToken');
      this.$router.push({
        name: 'login'
      });
    },
    getLoginStatus() {
      return this.$reqGet(USER_PROFILE, {
        id: this.user.id
      }, {hideLoading: true}).then(res => {
        this.user = res.data.data;
        this.user.supplier = res.data.supplier;
        this.user.points = res.data.points;
        this.saveUser(this.user);
        this.isLogin = true;
      })
    }
  },

  components: {
    [userHeader.name]: userHeader,
    // [orderGroup.name]: orderGroup,
    [ecouponGroup.name]: ecouponGroup,
    [userModule.name]: userModule,
  }
}
</script>


<style scoped lang="scss">
.tabbar-user {
	>div {
		margin-bottom: 10px;
	}
	&__quit {
			border: 0;
			border-radius: 0;
	}
}
.share_mask {
    background-color: black;
    opacity: 0.8;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
	height: 100%;
	z-index: 999;
    > img {
        width: 180px;
        position: absolute;
        right: 0;
        top: 0;
    }
}
</style>
